package com.artisan.booteventbus.service.impl;

import com.artisan.booteventbus.domain.MessageEvent;
import com.artisan.booteventbus.service.MessageChannel;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;

@Slf4j
public class EmailMessageChannel implements MessageChannel {
    @Override
    public boolean supports(MessageEvent event) {
        return "email".equals(event.getChannel());
    }

    @Override
    public CompletableFuture<Void> sendAsync(MessageEvent event) {
        return CompletableFuture.runAsync(() -> {
            // 模拟邮件发送
            System.out.println(Thread.currentThread().getName() + "- Sending email: " + event.getMessage());
            log.info("Sending email: {}", event.getMessage());
        });
    }
}
